class PhieuNhap < ActiveRecord::Base
  attr_accessible :tai_san_id, :nhan_vien_id, :ngay_nhap, :trang_thai, :so_luong, :nha_cung_cap_id
  belongs_to :tai_san, :foreign_key =>  "tai_san_id", :class_name => "TaiSan"
  belongs_to :nhan_vien, :foreign_key =>  "nhan_vien_id", :class_name => "NhanVien"
  belongs_to :nha_cung_cap, :foreign_key =>  "nha_cung_cap_id", :class_name => "NhaCungCap"

  validates_presence_of :tai_san_id, :nhan_vien_id, :ngay_nhap, :trang_thai, :so_luong



  def self.getAllbyNV(nvid)
    pn = PhieuNhap.joins(:tai_san).where(:nhan_vien_id => nvid)
    return pn_hash = pn.collect{ |c| {:MaTS => c.tai_san.MaTS, :TenTS => c.tai_san.TenTS, :SoLuong => c.tai_san.SLuong, :Ngay => c.ngay_nhap } }
  end
  def self.getAllbyTS(tsid)
    pn = PhieuNhap.joins(:tai_san).where(:tai_san_id => tsid)
    return pn_hash = pn.collect{ |c| {:NhanVIen => c.nhan_vien.TenNV, :SoLuong => c.tai_san.SLuong, :Ngay => c.ngay_nhap } }
  end
end
